
package kaizen.nomweb;

import java.io.FileInputStream;
import java.io.PrintStream;

import java.sql.*;

import oracle.jdbc.driver.OracleDriver;

// Referenced classes of package kaizen.nomweb:
//            utilerias

public class ejecuta
{

  public ejecuta()
  {
    url = "";
    user = "";
    pass = "";
    salidar = "";
  }

  public static String store(String s, String s1, int i, int j)
  {
    try
    {
      java.util.Properties properties = 
        utilerias.loadProperties("/kaizen/general.properties");
      url = utilerias.tomaProp("urlUniv", properties);
      user = utilerias.tomaProp("userUniv", properties);
      pass = utilerias.tomaProp("passwordUniv", properties);
    } catch (Exception exception)
    {
      System.out.println("Ocurrio un Error: " + exception);
    }
    int k = i + j;
    int l = 0;
    int i1 = 0;
    int j1 = 0;
    String s2 = "";
    String s3 = "";
    try
    {
      DriverManager.registerDriver(new OracleDriver());
      Connection connection = DriverManager.getConnection(url, user, pass);
      Statement statement = connection.createStatement();
      String s4 = "";
      for (int k1 = 1; k1 <= k; k1++)
        if (s4.equals(""))
          s4 = "?";
        else
          s4 = s4 + ",?";

      CallableStatement callablestatement = 
        connection.prepareCall("alter session set NLS_NUMERIC_CHARACTERS = '.,'");
      callablestatement.execute();
      callablestatement = 
          connection.prepareCall("{call " + s.substring(0, s.indexOf("(") + 
                                                        1) + s4 + ")}");
      int l1 = i;
      int i2 = j;
      for (int j2 = 1; j2 <= k; j2++)
      {
        String s5 = s.substring(s.indexOf(",", l) + 1, s.indexOf(",", l) + 2);
        if (l1 != 0)
          s3 = s1.substring(i1, s1.indexOf(",", i1));
        if (i2 > 0 && l1 == 0)
        {
          if (s5.equals("V"))
            callablestatement.registerOutParameter(j2, 12);
          if (s5.equals("N"))
            callablestatement.registerOutParameter(j2, 4);
          if (s5.equals("F"))
            callablestatement.registerOutParameter(j2, 6);
          i2--;
        }
        if (l1 > 0)
        {
          if (s5.equals("V"))
            if (s3.equals(""))
              callablestatement.setNull(j2, 12);
            else
              callablestatement.setString(j2, s3);
          if (s5.equals("N"))
            if (s3.equals(""))
              callablestatement.setNull(j2, 4);
            else
              callablestatement.setInt(j2, Integer.parseInt(s3));
          if (s5.equals("F"))
            if (s3.equals(""))
              callablestatement.setNull(j2, 6);
            else
              callablestatement.setFloat(j2, Float.parseFloat(s3));
          i1 = s1.indexOf(",", i1) + 1;
          System.out.println(i1);
          l1--;
        }
        l = s.indexOf(",", l) + 1;
        if (l1 == 0 && j1 == 0)
          j1 = l;
      }

      callablestatement.execute();
      for (int k2 = i + 1; k2 <= k; k2++)
      {
        int l2 = s.indexOf(",", j1) + 1;
        int i3 = s.indexOf(",", j1) + 2;
        String s6 = 
          s.substring(s.indexOf(",", j1) + 1, s.indexOf(",", j1) + 2);
        if (s6.equals("V"))
          salidar = salidar + callablestatement.getString(k2) + ";";
        if (s6.equals("N"))
          salidar = salidar + callablestatement.getInt(k2) + ";";
        if (s6.equals("F"))
          salidar = salidar + callablestatement.getFloat(k2) + ";";
        j1 = s.indexOf(",", j1);
      }

      if (salidar.indexOf("-") > 0)
      {
        statement.close();
        connection.close();
      } else
      {
        connection.rollback();
        statement.close();
        connection.close();
      }
    } catch (Exception exception1)
    {
      System.out.println("Ocurrio un error :" + exception1);
    }
    return salidar;
  }

  public static Connection getDBConnection()
  {
    try
    {
      java.util.Properties properties = 
        utilerias.loadProperties("/kaizen/general.properties");
      url = utilerias.tomaProp("urlUniv", properties);
      user = utilerias.tomaProp("userUniv", properties);
      pass = utilerias.tomaProp("passwordUniv", properties);
      DriverManager.registerDriver(new OracleDriver());
      Connection connection = DriverManager.getConnection(url, user, pass);
      return connection;
    } catch (Exception exception)
    {
      System.out.println("Ocurrio un Error en ejecuta.getDBConnection: " + 
                         exception);
    }
    return null;
  }

  static FileInputStream input;
  static String url = "";
  static String user = "";
  static String pass = "";
  static String salidar = "";

}
